<script type="text/javascript" src="/assets/js/jquery.hotkeys.min.js"></script>				<!--页面按键事件-->
<SCRIPT type="text/javascript">
var cubeid = "<#if cube??>${cube.id!''}</#if>";
var dimid = null;
	function selPath(path){
		loadURL('dashboard','#content',loadURL(path,"#datalist"),null,true);
		//loadURL(path,"#datalist");
	}
	var ztreesetting = {
		view: {
			showLine: false	,
			removeHoverDom: removeHoverDom,
			addHoverDom: addHoverDom
		},
		edit: {
			drag: {
				autoExpandTrigger: true,
				prev: dropPrev,
				inner: dropInner,
				next: dropNext
			},
			isCopy:true,
			enable: true,
			showRemoveBtn: false,
			showRenameBtn: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			beforeDrag: beforeDrag,
			beforeDrop: beforeDrop,
			beforeDragOpen: beforeDragOpen,
			onDrag: onDrag,
			onDrop: onDrop,
			onDblClick: doMetaDblClick,
			beforeCheck: zTreeBeforeCheck,
			onClick: zTreeOnClick
		}
	};
	function zTreeBeforeCheck(treeId, treeNode) {
	    return true;
	};
	
	/**
	* shift 键选中事件
	*/
	function zTreeOnClick(event, treeId, treeNode) {
		var parentId = $("#parent_ind").val();
		var treeObj = $.fn.zTree.getZTreeObj(treeId);
		var index = treeObj.getNodeIndex(treeNode); //获取到当前节点的序列
		var ind_measure = $("#ind_").val(); //获取到上一次选中的节点
		document.getElementById('ind_').value=index;  //将本次的获取的节点存入隐藏域中
		document.getElementById('parent_ind').value=treeNode.parentTId;
		if(event.shiftKey){
			if(ind_measure != null && ind_measure != undefined && ind_measure != ""){
				var pnodes =  treeObj.getNodes();
				for(var i = 0 ; i < pnodes.length ; i ++){
					if(parentId == null || parentId =="" || parentId == undefined){
						var node = treeObj.getNodeByTId(pnodes[i].tId); 
						treeObj.cancelSelectedNode(node);
						if((index <= i && i <= ind_measure) || (index >= i && i >= ind_measure)){
							treeObj.selectNode(node,true);
						}
					}else{
						var nodes = pnodes[i].children;
						if(nodes[0].parentTId == parentId){
							for(var j = 0 ; j < nodes.length ; j ++){
								var node = treeObj.getNodeByTId(nodes[j].tId); 
								treeObj.cancelSelectedNode(node);
								if((index <= j && j <= ind_measure) || (index >= j && j >= ind_measure)){
									treeObj.selectNode(node,true);
								}
							}
						}
					}
				}
			}
			treeObj.selectNode(treeNode,true);
		}
	};
	/**
	 *	双击编辑	
	 **/
	function doMetaDblClick(e, treeId, treeNode) {
		if(treeNode.metaid){
			$("#metaedit").show();
			$("#metaedit").attr("data-id",treeNode.metaid);
			$("#metaedit").attr("href","/${orgi}/dm/cube/${cube.id!''}/cubemetaedit/"+treeNode.metaid+".html");
			$("#metaedit").click();
		}
		return treeNode.metaid;
	}
	function dropPrev(treeId, nodes, targetNode) {
		return false;
	}

	function dropInner(treeId, nodes, targetNode) {
		return false;
	}
	function dropNext(treeId, nodes, targetNode) {
		return false;
	}

	var log, className = "dark", curDragNodes, autoExpandNode;
	function beforeDrag(treeId, treeNodes) {
		className = (className === "dark" ? "":"dark");
		for (var i=0,l=treeNodes.length; i<l; i++) {
			if (treeNodes[i].drag === false) {
				curDragNodes = null;
				return false;
			} else if (treeNodes[i].parentTId && treeNodes[i].getParentNode().childDrag === false) {
				curDragNodes = null;
				return false;
			}
		}
		curDragNodes = treeNodes;
		return true;
	}
	function beforeDragOpen(treeId, treeNode) {
		autoExpandNode = treeNode;
		return true;
	}
	
	function onDrag(event, treeId, treeNodes) {
		className = (className === "dark" ? "":"dark");
	}
	function onDrop(event, treeId, treeNodes, targetNode, moveType, isCopy) {
		className = (className === "dark" ? "":"dark");
		return true ;
	}
	function add(treeNode , data) {
		var zTree = $.fn.zTree.getZTreeObj("levelZtree") ;
		if (treeNode) {
			treeNode = zTree.addNodes(treeNode,eval(data));
		}	
	}
	function addHoverDom(treeId, treeNode) {
		if(treeNode.ismeta){
			var sObj = $("#" + treeNode.tId + "_span");
			if (treeNode.editNameFlag || $("#removeBtn_"+treeNode.tId).length>0) return;
			var addStr = "<span class='button remove' id='removeBtn_" + treeNode.tId
				+ "' title='remove node' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var btn = $("#removeBtn_"+treeNode.tId);
			if (btn) btn.bind("click", function(){
				art.confirm('请确认是否删除元数据？', function(){
					$("#cubeformid").attr("action","/${orgi}/dm/cube/"+treeNode.tableid+"/cubemetadel.html");
					$("#cubeformid").submit();
				} 
				, function(){});
				return false;
			});
		}
	};
	function removeHoverDom(treeId, treeNode) {
		if(treeNode.ismeta){
			$("#removeBtn_"+treeNode.tId).unbind().remove();
		}
	};
	
	
	function beforeDrop(treeId, treeNodes, targetNode, moveType, isCopy) {
		className = (className === "dark" ? "":"dark");
		
		if(treeId=="levelZtree"){
			if(dimid !="") {
				for(i=0 ; i<treeNodes.length ; i++){
					var treeNode = treeNodes[i] ;
					if(treeNode.isParent){
						var nodes = treeNode.children ;
						for(inx = 0 ; inx < nodes.length ; inx++){
							var subNode = nodes[inx] ;
							loadURL('/${orgi}/dm/cube/leveladd/'+dimid+'/'+subNode.tpid+'/'+subNode.cubeid+'/'+encodeURIComponent(subNode.table)+'/'+encodeURIComponent(subNode.colum)+'/'+encodeURIComponent(treeNode.oldname==undefined?treeNode.colum:treeNode.oldname)+'.html','#tempdiv' ,
								function(){
									loadURL('/${orgi}/dm/cube/'+dimid+'/levellist.html', $("#levellist_div") , null);
								});
						}
					}
	
					if(treeNode.cubeid){
						loadURL('/${orgi}/dm/cube/leveladd/'+dimid+'/'+treeNode.tpid+'/'+treeNode.cubeid+'/'+encodeURIComponent(treeNode.table)+'/'+encodeURIComponent(treeNode.colum)+'/'+encodeURIComponent(treeNode.oldname==undefined?treeNode.colum:treeNode.oldname)+'.html',"#levellist_div",null);
					}
				}
			} else {
				artDialog.alert("请先选择维度！");
			}
		}
		if(treeId=="measureZtree"){
			for(i=0 ; i<treeNodes.length ; i++){
				var treeNode = treeNodes[i] ;
				if(treeNode.isParent){
					var nodes = treeNode.children ;
					for(inx = 0 ; inx < nodes.length ; inx++){
						var subNode = nodes[inx] ;
						loadURL('/${orgi}/dm/cube/measureadd/'+subNode.cubeid+'/'+encodeURIComponent(subNode.table)+'/'+encodeURIComponent(subNode.colum)+'/'+encodeURIComponent(treeNode.oldname==undefined?treeNode.colum:treeNode.oldname)+'.html','#tempdiv' ,
							function(){
								loadURL('/${orgi}/dm/cube/'+subNode.cubeid+'/measurelist'+'.html', $("#measure_div") , null);
							});
					}
				}
				if(treeNode.cubeid){
					loadURL('/${orgi}/dm/cube/measureadd/'+treeNode.cubeid+'/'+encodeURIComponent(treeNode.table)+'/'+encodeURIComponent(treeNode.colum)+'/'+encodeURIComponent(treeNode.oldname==undefined?treeNode.colum:treeNode.oldname)+'.html',"#measure_div" ,null);
				}
			}
		}

		return false;
	}
	var cubeMeta =[
		<#if cube?? && cube.metadata??>
		<#list cube.metadata as table>
			<#if table_index gt 0>,</#if>{ id:${100+table_index} , pId:0,title:"${table.tb.name!''}", name:"<#if table.tb.name?length gt 30>${table.tb.name[0..30]}...<#else>${table.tb.name!''}</#if><#if table.tb.groupid??>【${table.tb.groupid!''}】</#if><#if table.mtype?? && table.mtype == '0'>  （主表）  </#if>" ,tableid:"${table.id!''}" ,metaid:"${table.id!''}" , icon:"/assets/images/table2.png",ismeta:true ,  open:false , type:"table"}
			<#if table.tb.tableproperty??>
			<#list table.tb.tableproperty as tp>
			,{ id:${(100+table_index)*1000+tp_index} , pId:${100+table_index}, name:"<#if tp.name?length gt 30>${tp.name[0..30]}...<#else>${tp.name!''}</#if><#if tp.groupid??>【${tp.groupid!''}】</#if>" ,<#if tp.groupid??>oldname:"${tp.groupid!''}",</#if> cubeid:"${cube.id!''}" , dropInner:false , table:"${table.tb.tablename!''}" , tpid:"${tp.id!''}", icon:"/assets/images/frame_field.png", tptype:"field", colum:"${tp.name!''}"}
			</#list>
			</#if>
		</#list>
		</#if>
	];

	$().ready(function() {
		dimid = $("#dimid_hidden").val();
		var metaDataZtree = $.fn.zTree.init($("#metadataZtree"), ztreesetting, cubeMeta);
		$("body").bind('keydown', 'del',function (evt){
			var measureZtreeObject = $.fn.zTree.getZTreeObj("measureZtree");
			var nodes = measureZtreeObject.getSelectedNodes();
			if(nodes.length >0){
				art.confirm('您确定要删除此指标吗？' , 
				function(){
					for(var i = 0 ; i < nodes.length ; i ++){
						measureZtreeObject.removeNode(nodes[i],true);
						loadURL('/${orgi}/dm/cube/'+nodes[i].cubeid+'/measuredelo/'+nodes[i].lid+'.html' , "#measure_div" , null);
					}
				} , function(){});
			}
			return false;
		});
	});
	function cubeLevelLoad(id){
		$("#level_tbody tr").attr("class","");
		$("#level_tr_"+id).attr("class","odd cubecur");
		$("#dimid_hidden").val(id);
		dimid = $("#dimid_hidden").val();
		loadURL('/${orgi}/dm/cube/'+id+'/levellist.html', $("#levellist_div") , null);
	}
</SCRIPT>
<form id="cubeformid" action="" >
</form>
<div class="rs_layout_top breadCrumbWrap">
	<div class="breadCrumbStart">您当前的位置是在：</div>
	<ul class="breadCrumb">
		<li class="bc_ithems"><a href="/${orgi}/dm/cube/index.html">数据模型管理</a></li>
		<#if locationdics??>
			<#list locationdics?reverse as local>
		<li class="bc_ithems">
			<a href="/${orgi}/dm/cube/cubedic/${local.id!''}.html">${local.name!''	}</a>
		</li>	
			</#list>
		</#if>
		<li class="bc_ithems"><a href="/${orgi}/dm/cube/cubedesign/${cube.id!''}.html">${cube.name!''}</a></li>
	</ul>
	<ul class="controlButtons">
		<li data-toggle="ajax" id="dbsourceimport" data-width="720" href="/${orgi}/dm/cube/${cube.id!''}/dbsourceimport.html" class="cbtn-icon-45" title="导入元数据"></li>
		<li class="cbtn-icon-7" data-toggle="ajax" id="dimensionadd" data-width="650" href="/${orgi}/dm/cube/${cube.id!''}/dimensionadd.html" title="添加维度"></li>
		<li class="cbtn-icon-1051" href="/${orgi}/dm/cube/${cube.id!''}/cubevalid.html" data-toggle="ajax" data-width="450" title="验证数据模型"></li>
		<li class="cbtn-icon-47" data-toggle="ajax" id="cubepublish" data-width="560" href="/${orgi}/dm/cube/${cube.id!''}/cubepublish.html" title="发布数据模型"></li>
		<!-- <li class="cbtn-icon-48" onclick="art.confirm('您确定要删除此模型吗？' , function(){location.href='/${orgi}/dm/cube/${cube.typeid!''}/cubedelo/${cube.id!''}.html'} , function(){})" title="删除数据模型"></li> -->
		<li class="cbtn-icon-49" onclick="location.href='/${orgi}/dm/cube/${cube.id!''}/cubedownload.html'" title="导出数据模型文件"></li>
	</ul>
</div>
<div class="rs_layout_left" resizable="true" style="width:280px;">
	<div class="lftTreeWrap">
		<div class="rs_layout_top"><div class="task_title2">模型元数据</div></div>
		<div class="ztree" id="metadataZtree"></div>
	</div>
	<i style="display:none;" data-toggle="ajax" id="metaedit" data-width="480" class="cbtn-icon-45" title="修改元数据"></i> 
</div>
<!--<div class="rs_layout_right" style="width:300px;"></div>-->
<div class="rs_layout_center">
<input type="hidden" id="dimid_hidden" value="<#if dim??>${dim.id!''}</#if>">
<input id="parent_ind" type="hidden" name="parent_ind" value=""/>
<input id="ind_" type="hidden" name="ind_" value=""/>
	<div class="rs_layout">
		<div class="rs_layout_top" style="height:50%; border-bottom: solid 1px #d7d7d7">
			<div class="rs_layout">
				<div class="rs_layout_right" style="width: 230px; border-left: solid 1px #D7D7D7">
					<div class="rs_layout">
						<div class="rs_layout_top">
							<div class="task_title2">
								<span onclick="art.confirm('确认清空该维度下的成员？',function(){loadURL('/${orgi}/dm/cube/'+dimid+'/levelclear.html', $('#levellist_div') , null);},function(){});"class="tabIcon top_icon5" style="float: right;">&nbsp;</span>
								维度成员
							</div>
						</div>
						<div class="rs_layout_center" id="levellist_div">
						<#include "/pages/datamodel/cube/levellist.html"/>
						</div>
					</div>

				</div>
				<div class="rs_layout_center">
					<div class="rs_layout">
						<div class="rs_layout_top">
							<div class="task_title2">维度</div>
							
						</div>
						<div class="rs_layout_center" id="dimdiv">
							<#include "dimlist.html"/>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="rs_layout_center">
			<div class="rs_layout">
				<div class="rs_layout_right" style="width: 230px; border-left: solid 1px #D7D7D7">
					<div class="rs_layout">
						<div class="rs_layout_top">
							<div class="task_title2">
								<span onclick="art.confirm('确认清空指标？',function(){loadURL('/${orgi}/dm/cube/${cube.id!''}/measureclear.html', '#measure_div' , null)},function(){});" class="tabIcon top_icon5" style="float: right;"></span>
								指标
							</div>
						</div>
						<div class="rs_layout_center" id="measure_div">
						<#include "/pages/datamodel/cube/measurelist.html"/>
						</div>
					</div>
					
				</div>
				<div class="rs_layout_center">
					<div class="rs_layout" id="auth">
						<#include "/pages/datamodel/cube/cubeauth.html"/>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>